<template>
<div id="publish">

<!-- // 头部 -->
<!-- <van-pull-refresh v-model="isLoading" @refresh="onRefresh">

<list :list="list"></list>
</van-pull-refresh> -->

 <!-- <scroller :on-infinite="onRefresh"  noDataText="--我也是有底线的--"  >
<list :list="list"></list>
</scroller> -->

<!--   <scroller :on-infinite="infinite"  :noDataText="noDataText" ref="my_scroller">
<list :list="list"></list>


</scroller> -->

<!-- <list :list="list"></list>
 <div class="shop_container">

            <div class="shop_header">

            </div>

        </div> -->

<div class="list">
<list
:list="list"
 v-infinite-scroll="loadMore"
  infinite-scroll-disabled="loading"
  infinite-scroll-distance="0"

  >
  </list>
<div class="more" v-if="moreshow" >

<img src="static/img/more.png" alt="">
</div>

<van-loading type="spinner" v-if="isloashow"  class="loa"/>
</div>
 <div  style="height:75px;"></div>

</div>


</template>



<script>
 import event from '@/pages/Commons/event.js'
  import AppFooter from '@/pages/Commons/Footer.vue'
import List from '@/pages/publish/comments/list.vue'
import Axios from 'axios';
import BScroll from 'better-scroll'


  import Vue from 'vue'
  import VueScroller from 'vue-scroller'
import { Toast } from 'vant';

  Vue.use(VueScroller)
export default{
  components:
  {
    AppFooter,List
  },
data(){
  return{
  isLoading: true,
  isloashow:false,
count:15,
list:[],
noDataText:'我也是有底线的',
imagelist:[],
loading:false,
moreshow:false
  }
},
 props: {
        type: '',
        search:''
    },

methods:{
loadMore() {
  this.isloashow=true;
  this.loading = false;
console.log(1111)
this.onRefresh()

},
//   infinite:function(){
//      var pages =this.count;
//        pages += 15;
//    
//       this.timeout = setTimeout(()=>{
//         if (this.list.length >= 5) {
//          this.$refs.my_scroller.finishInfinite(true);
// var userid=localStorage.getItem('userid');
//     var token=localStorage.getItem('token');
//     var list =this.list;
// Axios.get('/api/publish/list',{
//   headers: {
//             'Authorization': 'Bearer ' + token
//         },
//         params: {
//           page: pages,
//         }
//       }).then(response=>{
//           console.log(response);
//                   var li =response.data.data.list;
//                   var imagelist=response.data.data.pic;
//               for(var i in li){
//                 this.list.push(li[i])
//               }

//         for(var i in imagelist){
//         this.imagelist.push(imagelist[i])

//         }
//       })
//         }else{
//           this.$refs.my_scroller.finishInfinite(false);
//         }
//         //this.$refs.my_scroller.resize();//已弃用，

//       }, 1500)


//     }, 
   
    getlist(pages){
 var userid=localStorage.getItem('userid');
    var token=localStorage.getItem('token');
    var list =this.list;
Axios.get('/api/publish/list',{
  headers: {
            'Authorization': 'Bearer ' + token
        },
        params: {
          page: pages,
          type:this.type
        }
      })
        .then((response) => {
       console.log(response);
   if(response.data.status==0){

   if(response.data.data.list.length==0){

          this.moreshow=true

        }
     setTimeout(() => {
        // this.$toast('加载成功');
        if(response.data.data.list.length==0){
          this.loading=true
          this.isloashow=false
          this.moreshow=false
          // Toast({
          //   message:'加载完毕',
          //   duration:500
          // })
        }

        this.count+=15;
      }, 700);
        // list.push(response.data.data.list);
        // list =response.data.data.list
      var li =response.data.data.list;

      for(var i in li){
         this.list.push(li[i])
      }

   }
      })

    },
    getagin(){
      var userid=localStorage.getItem('userid');
    var token=localStorage.getItem('token');

    Axios.get('/api/publish/list',{
    headers: {
            'Authorization': 'Bearer ' + token
        },
        params: {

          type:this.type
        }
      })
        .then((response) => {
       console.log(response);
   if(response.data.status==0){

      var li =response.data.data.list;

     this.list=li
    console.log(li)
   }
      })
    },
 getsearch(){
      var userid=localStorage.getItem('userid');
    var token=localStorage.getItem('token');

    Axios.get('/api/publish/list',{
    headers: {
            'Authorization': 'Bearer ' + token
        },
        params: {

          cate:this.search
        }
      })
        .then((response) => {
       console.log(response);
   if(response.data.status==0){

      var li =response.data.data.list;

     this.list=li
    console.log(li)
   }
      })
    },


  onRefresh() {

    var pages =this.count;
    this.getlist(pages)

    }
},
mounted(){
  this.getlist()
   event.$on('event', (data) => {
        console.log(data)
        if(data==1){
           this.getagin()

        }else{
          console.log(仓库event出错)
        }

      })

   event.$on('count', (data) => {
        console.log(data)
        if(data==1){
           this.getagin()

        }else{
          console.log(仓库event出错)
        }
      })

 event.$on('type', (data) => {

        this.type=data
           this.getagin()


      })

 event.$on('value', (data) => {

        this.search=data
           this.getsearch()


      })



}

}
</script>



<style>
.more{width: 35%;height: 35%;margin-left: 30%;margin-top: 15%}
.more img{width: 100%;height: 100%}
.list{height: 100%}
.loa{margin-left: 45%}
#publish{

}

  #message{

}
.headers{
  width: 100%;height: 12rem;background:#259E7B;position: relative
}
.header{
    background: #259e7b;
    color: white
}
.van-icon-arrow::before,.van-nav-bar__text{color: white}

</style>
